home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qiodevice.h.z / qiodevice.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  4.2 KB  |  143 lines

  1. /****************************************************************************
  2. ** $Id: qiodevice.h,v 2.6 1998/07/03 00:09:46 hanord Exp $
  3. **
  4. ** Definition of QIODevice class
  5. **
  6. ** Created : 940913
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QIODEVICE_H
  25. #define QIODEVICE_H
  26.  
  27. #ifndef QT_H
  28. #include "qglobal.h"
  29. #endif // QT_H
  30.  
  31.  
  32. // IO device access types
  33.  
  34. #define IO_Direct        0x0100        // direct access device
  35. #define IO_Sequential        0x0200        // sequential access device
  36. #define IO_Combined        0x0300        // combined direct/sequential
  37. #define IO_TypeMask        0x0f00
  38.  
  39. // IO handling modes
  40.  
  41. #define IO_Raw            0x0040        // raw access (not buffered)
  42. #define IO_Async        0x0080        // asynchronous mode
  43.  
  44. // IO device open modes
  45.  
  46. #define IO_ReadOnly        0x0001        // readable device
  47. #define IO_WriteOnly        0x0002        // writeable device
  48. #define IO_ReadWrite        0x0003        // read+write device
  49. #define IO_Append        0x0004        // append
  50. #define IO_Truncate        0x0008        // truncate device
  51. #define IO_Translate        0x0010        // translate CR+LF
  52. #define IO_ModeMask        0x00ff
  53.  
  54. // IO device state
  55.  
  56. #define IO_Open            0x1000        // device is open
  57. #define IO_StateMask        0xf000
  58.  
  59.  
  60. // IO device status
  61.  
  62. #define IO_Ok            0
  63. #define IO_ReadError        1        // read error
  64. #define IO_WriteError        2        // write error
  65. #define IO_FatalError        3        // fatal unrecoverable error
  66. #define IO_ResourceError    4        // resource limitation
  67. #define IO_OpenError        5        // cannot open device
  68. #define IO_ConnectError        5        // cannot connect to device
  69. #define IO_AbortError        6        // abort error
  70. #define IO_TimeOutError        7        // time out
  71.  
  72. #undef    TB
  73. #define TB(x) ((ioMode & (x)) == (x))
  74.  
  75.  
  76. class QIODevice                    // IO device class
  77. {
  78. public:
  79.     QIODevice();
  80.     virtual ~QIODevice();
  81.  
  82.     int         flags()  const { return ioMode; }
  83.     int         mode()      const { return ioMode & IO_ModeMask; }
  84.     int         state()  const { return ioMode & IO_StateMask; }
  85.  
  86.     bool     isDirectAccess()     const { return TB(IO_Direct); }
  87.     bool     isSequentialAccess() const { return TB(IO_Sequential); }
  88.     bool     isCombinedAccess()   const { return TB(IO_Combined); }
  89.     bool     isBuffered()          const { return !TB(IO_Raw); }
  90.     bool     isRaw()          const { return TB(IO_Raw); }
  91.     bool     isSynchronous()      const { return !TB(IO_Async); }
  92.     bool     isAsynchronous()     const { return TB(IO_Async); }
  93.     bool     isTranslated()          const { return TB(IO_Translate); }
  94.     bool     isReadable()          const { return TB(IO_ReadOnly); }
  95.     bool     isWritable()          const { return TB(IO_WriteOnly); }
  96.     bool     isReadWrite()          const { return TB(IO_ReadWrite); }
  97.     bool     isInactive()          const { return state() == 0; }
  98.     bool     isOpen()          const { return state() == IO_Open; }
  99.  
  100.     int         status() const { return ioSt; }
  101.     void     resetStatus()    { ioSt = IO_Ok; }
  102.  
  103.     virtual bool open( int mode ) = 0;
  104.     virtual void close() = 0;
  105.     virtual void flush() = 0;
  106.  
  107.     virtual uint size()      const = 0;
  108.     virtual int     at()      const;
  109.     virtual bool at( int );
  110.     virtual bool atEnd()  const;
  111.     bool     reset() { return at(0); }
  112.  
  113.     virtual int     readBlock( char *data, uint len ) = 0;
  114.     virtual int     writeBlock( const char *data, uint len ) = 0;
  115.     virtual int     readLine( char *data, uint maxlen );
  116.  
  117.     virtual int     getch() = 0;
  118.     virtual int     putch( int ) = 0;
  119.     virtual int     ungetch( int ) = 0;
  120.  
  121. protected:
  122.     void     setFlags( int f ) { ioMode = f; }
  123.     void     setType( int );
  124.     void     setMode( int );
  125.     void     setState( int );
  126.     void     setStatus( int );
  127.     int         index;
  128.  
  129. private:
  130.     int         ioMode;
  131.     int         ioSt;
  132.  
  133. private:    // Disabled copy constructor and operator=
  134.     QIODevice( const QIODevice & );
  135.     QIODevice &operator=( const QIODevice & );
  136. };
  137.  
  138.  
  139. #undef    TB
  140.  
  141.  
  142. #endif // QIODEVICE_H
  143.